package com.arsn.myf.flow.controller;

import com.arsn.myf.common.util.result.R;
import com.arsn.myf.flow.entity.FlowModel;
import com.arsn.myf.flow.service.FlowEngineService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;

/**
 * 流程模型控制器
 * @author zhongrj
 * @date 2022-10-11
 */
@RestController
@RequestMapping("/flow/model")
@AllArgsConstructor
@Api(value = "流程模型控制器",tags = "流程模型控制器")
public class FlowModelController {

	private final FlowEngineService flowEngineService;

	/**
	 * 分页
	 * @param flow flow 实体
	 * @param page page 对象
	 */
	@GetMapping("/list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "modelKey", value = "模型标识", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "模型名称", paramType = "query", dataType = "string")
	})
	@ApiOperation(value = "分页", notes = "传入flow")
	public R list(Page<FlowModel> page, FlowModel flow) {
		return R.data(flowEngineService.selectPageDeptList(page, flow));
	}

	/**
	 * 删除
	 * @param ids 需要删除的id
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入主键集合")
	public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
		return R.status(flowEngineService.removeByIds(Arrays.asList(ids.split(","))));
	}

	/**
	 * 部署模型
	 * @param flow 模型
	 */
	@PostMapping("/deploy")
	@ApiOperation(value = "部署")
	public R deploy(@RequestBody FlowModel flow) {
		return R.status(flowEngineService.deployModel(flow));
	}

	/**
	 * 获取流程节点图
	 * @param processDefinitionId 流程定义id
	 * @param processInstanceId 流程实例id
	 * @return
	 */
	@GetMapping("/process-view")
	@ApiOperation(value = "获取流程节点图", notes = "传入流程实例id")
	public R processView(@ApiParam(value = "流程定义id") @RequestParam String processDefinitionId,
						 @ApiParam(value = "流程实例id") @RequestParam String processInstanceId) {
		return R.data(flowEngineService.processView(processDefinitionId,processInstanceId));
	}

}
